package com.watson.todolist.database;

import com.watson.todolist.constants.DatabaseConstants;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * The database helper class handles creating, deleting, and updating the
 * database and its tables.
 * 
 * @author Donnie Ward
 * 
 * @since 1.0
 */
public class DatabaseHelper extends SQLiteOpenHelper {
	/**
	 * The database name
	 */
	private final static String DATABASE_NAME = DatabaseConstants.DB_NAME;
	/**
	 * The database version number
	 */
	private final static int DATABASE_VERSION = 1;

	/**
	 * Database helper constructor which makes a call to the SQLiteOpenHelper
	 * constructor
	 * 
	 * @param - A reference to the class creating a DatabaseHelper object
	 */
	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite
	 * .SQLiteDatabase)
	 */
	@Override
	public void onCreate(SQLiteDatabase database) {
		// Create table
		UserAccountTable.onCreate(database);
		TodoItemTable.onCreate(database);
		TagItemTable.onCreate(database);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite
	 * .SQLiteDatabase, int, int)
	 */
	@Override
	public void onUpgrade(SQLiteDatabase database, int oldVersion,
			int newVersion) {
		// Upgrade table
		UserAccountTable.onUpgrade(database, oldVersion, newVersion);
		TodoItemTable.onUpgrade(database, oldVersion, newVersion);
		TagItemTable.onUpgrade(database, oldVersion, newVersion);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onOpen(android.database.sqlite
	 * .SQLiteDatabase)
	 */
	@Override
	public void onOpen(SQLiteDatabase database) {

	}
}
